package com.rent.weixin.service.impl;

import com.rent.weixin.config.WeixinConfig;
import com.rent.weixin.service.IWeixinBaseService;
import com.rent.weixin.utils.SHA1;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author zhang
 * @create 2021/6/19 10:31
 */
@Slf4j
@Service
public class WeixinBaseServiceImpl implements IWeixinBaseService {

    @Autowired
    private WeixinConfig weixinConfig;


    @Override
    public boolean checkSignature(String timestamp, String nonce, String signature) {
        try {
            return SHA1.gen(weixinConfig.getToken(), timestamp, nonce)
                    .equals(signature);
        } catch (Exception e) {
            log.error("Checking signature failed, and the reason is :" + e.getMessage());
            return false;
        }
    }


}
